package com.atguigu.eduservice.controller;


import com.atguigu.annotation.WebLog;
import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author 陈烨庆
 * @since 2022-01-22
 */
@RestController
@RequestMapping("/eduservice/edu-subject")
@CrossOrigin
@Api("课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    // 添加课程分类
    // 获取上传过来的文件，读取里面的内容
    @ApiOperation("添加课程分类")
    @WebLog("添加课程分类")
    @PostMapping("addSubject")
    public R addSubject(MultipartFile file) {

        subjectService.saveSubject(file, subjectService);

        return R.ok();
    }

    @ApiOperation("嵌套数据列表")
    @WebLog("嵌套数据列表")
    @GetMapping("getAllSubject")
    public R getAllSubject() {
        List<OneSubject> list = subjectService.getAllSubject();
        return R.ok().data("list", list);
    }

}

